
package com.bstek.urule.console.repository.updater;

import com.bstek.urule.RuleException;
import org.dom4j.Document;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

import java.io.IOException;
import java.io.StringWriter;

/**
 * @author Jacky.gao
 * @since 2015年8月4日
 */
public abstract class AbstractReferenceUpdater implements ReferenceUpdater {
    protected String xmlToString(Document doc) {
        StringWriter stringWriter = new StringWriter();
        OutputFormat xmlFormat = new OutputFormat();
        xmlFormat.setEncoding("UTF-8");
        XMLWriter xmlWriter = new XMLWriter(stringWriter, xmlFormat);
        try {
            xmlWriter.write(doc);
            xmlWriter.close();
            return stringWriter.toString();
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuleException(e);
        }
    }
}
